from flask import Flask, request, jsonify

app = Flask(__name__)


# 根路径的 GET 接口
@app.route('/', methods=['GET'])
def home():
    return jsonify({"message": "Welcome to the API Service!"})


# 带参数的 GET 接口示例
@app.route('/add', methods=['GET'])
def add_numbers():
    # 获取 URL 参数
    num1 = request.args.get('num1', type=float)
    num2 = request.args.get('num2', type=float)

    if num1 is None or num2 is None:
        return jsonify({"error": "Please provide both num1 and num2 parameters"}), 400

    result = num1 + num2
    return jsonify({"result": result})


if __name__ == '__main__':
    # 运行应用（默认端口5000）
    app.run(debug=True)